package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.RouteInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/28 13:53
 * @Description:
 */
@Mapper
public interface RouteInfoMapper extends BaseMapper<RouteInfo> {
    @Select("select * from route_info where route_id=#{routeId}")
    public RouteInfo findRouteById(@Param("routeId") Long routeId);

    @Delete("delete from route_info where route_id=#{routeId}")
    public Integer deleteRouteById(@RequestParam("routeId") Long routeId);

    @Insert("insert into route_info(route_id, route_company, route_resource_province, route_resource_city, route_resource_country, route_resource_person, route_resource_person_phone," +
            "route_resource_address, route_destination_province, route_destination_city, route_destination_country, route_destination_person, route_destination_person_phone, route_destination_address," +
            "route_price_light, route_price_heavy, create_time, update_time) values(#{routeInfo.routeId}, #{routeInfo.routeCompany}, #{routeInfo.routeResourceProvince}, " +
            "#{routeInfo.routeResourceCity}, #{routeInfo.routeResourceCountry}, #{routeInfo.routeResourcePerson}, #{routeInfo.routeResourcePersonPhone}, #{routeInfo.routeResourceAddress}, " +
            "#{routeInfo.routeDestinationProvince}, #{routeInfo.routeDestinationCity}, #{routeInfo.routeDestinationCountry}, #{routeInfo.routeDestinationPerson}, #{routeInfo.routeDestinationPersonPhone}, " +
            "#{routeInfo.routeDestinationAddress}, #{routeInfo.routePriceLight}, #{routeInfo.routePriceHeavy}, #{routeInfo.createTime}, #{routeInfo.updateTime})")
    public Integer insertRoute(@Param("routeInfo") RouteInfo routeInfo);

    @Update("update route_info set route_company=#{routeCompany}, route_resource_province=#{routeResourceProvince}, " +
            "route_resource_city=#{routeResourceCity}, route_resource_country=#{routeResourceCountry}, route_resource_person=#{routeResourcePerson}, route_resource_person_phone=#{routeResourcePersonPhone}, " +
            "route_resource_address=#{routeResourceAddress}, route_destination_province=#{routeDestinationProvince}, route_destination_city=#{routeDestinationCity}, route_destination_country=#{routeDestinationCountry}," +
            "route_destination_person=#{routeDestinationPerson}, route_destination_person_phone=#{routeDestinationPersonPhone}, route_destination_address=#{routeDestinationAddress}," +
            "route_price_light=#{routePriceLight}, route_price_heavy=#{routePriceHeavy} where route_id=#{routeId}")
    public Integer updateRouteByRouteId(@RequestParam("routeInfo") RouteInfo routeInfo);

    @Select("select * from route_info where route_company=#{routeCompany}")
    public List<RouteInfo> findRouteByComName(@Param("routeCompany") String routeCompany);

    //取最后6条数据
    @Select("select * from route_info order by route_id desc limit 6")
    public List<RouteInfo> findLast6Route();

    //根据出发地和到达地选择物流专线
    @Select("select * from route_info where route_resource_province=#{rProvince} and route_resource_city=#{rCity} and route_resource_country=#{rCountry} and " +
            "route_destination_province=#{dProvince} and route_destination_city=#{dCity} and route_destination_country=#{dCountry}")
    public List<RouteInfo> findRouteByRAndD(@Param("rProvince") String rProvince,@Param("rCity") String rCity,@Param("rCountry") String rCountry,
                                            @Param("dProvince") String dProvince,@Param("dCity") String dCity,@Param("dCountry") String dCountry);

}
